package com.axend.aerosense.base.utils;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.Toast;

import com.axend.aerosense.base.BaseModuleInit;

/**
 * Toast工具类
 */
public class ToastUtils {

    private static boolean IS_SHOW = true;
    private static Context context = BaseModuleInit.getAppContext();
    private static boolean isShow = false;
    private static CountDownTimer countDownTimer;

    public static void shortToast(String msg){
        if (IS_SHOW)
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    public static void shortToast(int msg){
        if (IS_SHOW)
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }

    public static void longToast(String msg){
        if (IS_SHOW)
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    public static void longToast(int msg){
        if (IS_SHOW)
            Toast.makeText(context, msg, Toast.LENGTH_LONG).show();
    }

    private static void testToast(){
        //构建Toast
        final Toast toast = Toast.makeText(context, "测试文字", Toast.LENGTH_SHORT);
        if (isShow && countDownTimer != null){
            countDownTimer.cancel();
            toast.cancel();
        }
        countDownTimer = new CountDownTimer(3 * 1000, 1000) {
            @Override
            public void onTick(long millisUntilFinished) {
                if (toast != null){
                    toast.show();
                }
            }

            @Override
            public void onFinish() {
                if (toast != null){
                    toast.show();
                    countDownTimer.cancel();
                    isShow = false;
                }
            }
        };


    }

}
